import http from '@/utils/http';
// 获取后台用户列表
export function getAllAdminUser() {
  return http({
    url: '/getAdmins.do',
    method: 'get',
  });
}
// 删除后台用户
export function deleteAdminUser(ids: number[] | string[]) {
  return http({
    url: '/deleteAdmins.do',
    method: 'post',
    data: [...ids.map((id) => ({ key: id }))],
  });
}
// 修改用户信息
export function modifyAdminUserInfo(data: {
  id: number;
  username: string;
  password: string;
  roles: number[] | string[];
  status: number;
}) {
  return http({
    url: '/updateAdmins.do',
    method: 'post',
    data: {
      key: data.id,
      username: data.username,
      password: data.password,
      role: data.roles.map((id) => ({ key: id })),
      status: data.status,
    },
  });
}
// 添加后台用户
export function addAdminUser(data: {
  username: string;
  password: string;
  role: number[] | string[];
  status: number | string;
}) {
  return http({
    url: '/addAdmin.do',
    method: 'post',
    data: {
      username: data.username,
      password: data.password,
      role: data.role.map((item) => {
        return { key: Number(item) };
      }),
      status: Number(data.status),
    },
  });
}
